<!doctype html>
<html class="no-js">
<head>
<% include("/common/admin_head.html",{title: '添加/编辑导航', validatorJS: true}){}%>
<%var isAdd = false;
  var isEdit = false;
  if(isEmpty(navigation.id)){
	isAdd = true;
  }else{	
	isEdit = true;
  }%>
</head>
<body>
<div class="admin-content">
  <div class="admin-content-body">
    <div class="am-cf app-padding-title">
      <div class="am-fl am-cf">
        <strong class="am-text-primary am-text-lg">内容管理</strong> / <small><%if(isAdd){%>添加导航<%}else{%>编辑导航<%}%></small>
      </div>
    </div>
  
    <hr data-am-widget="divider" class="am-divider am-divider-dashed am-margin-0" />
    
    <form class="validator-form" action="<%if (isAdd){%>${base}/navigation/save<%}else{%>${base}/navigation/update<%}%>" method="post">
    <input type="hidden" name="navigation.id" value="${navigation.id!}" />
    <div class="am-form am-margin am-form-horizontal">
      <div class="am-form-group am-form-group-sm">
        <label class="am-u-sm-4 am-u-md-3 am-text-right am-form-label">名称</label>
        <div class="am-u-sm-8 am-u-md-9">
          <input type="text" id="name" class="am-form-field" name="navigation.name" value="${navigation.name!}" required />
          <div class="am-text-warning am-margin-top-xs am-text-xs">${nameMessages!}</div>
        </div>
      </div>
      <div class="am-form-group am-form-group-sm">
        <label class="am-u-sm-4 am-u-md-3 am-text-right am-form-label">系统内容</label>
        <div class="am-u-sm-8 am-u-md-9">
          <select id="systemUrl" data-am-selected="{btnWidth: '100%', maxHeight: '200px', btnSize: 'sm', btnStyle: 'secondary'}">
            <option value=""></option>
            <optgroup label="文章分类">
            <%for(list in articleCategoryTreeList){%>
            <option value="/shop/article/list?id=${list.id}"<%if (("/shop/article/list?id=" + list.id) == navigation.url!){%> selected <%}%>>
              <%if (list.level != 0){%>
              <%for( i in range(0,list.level)){%>--<%}%>
              <%}%>
              ${list.name}
            </option>
            <%}%>
            </optgroup>
            <optgroup label="商品分类">
            <%for(list in productCategoryTreeList){%>
		    <option value="/shop/product/list?id=${list.id}"<%if (("/shop/product/list?id=" + list.id) == navigation.url!){%> selected <%}%>>
		      <%if (list.level != 0){%>
			  <%for( i in range(0,list.level)){%>--<%}%>
			  <%}%>
			  ${list.name}
			</option>
			<%}%>
            </optgroup>
          </select>
        </div>
      </div>
      <div class="am-form-group am-form-group-sm">
        <label class="am-u-sm-4 am-u-md-3 am-text-right am-form-label">链接地址</label>
        <div class="am-u-sm-8 am-u-md-9">
          <input type="text" id="url" class="am-form-field" name="navigation.url" value="${navigation.url!}" required />
          <div class="am-text-warning am-margin-top-xs am-text-xs">${urlMessages!}</div>
        </div>
      </div>
      <div class="am-form-group am-form-group-sm">
        <label class="am-u-sm-4 am-u-md-3 am-text-right am-form-label">位置</label>
        <div class="am-u-sm-8 am-u-md-9">
          <select name="position" data-am-selected="{btnWidth: '100%', maxHeight: '200px', btnSize: 'sm', btnStyle: 'secondary'}">
            <option value="top" <%if (isAdd || navigation.position! == "top"){%>selected="selected" <%}%>>${i18n("Position.top")}</option>
			<option value="middle" <%if (isAdd || navigation.position! == "middle"){%>selected="selected" <%}%>>${i18n("Position.middle")}</option>
			<option value="bottom" <%if (isAdd || navigation.position! == "bottom"){%>selected="selected" <%}%>>${i18n("Position.bottom")}</option>
          </select>
        </div>
      </div>
      <div class="am-form-group am-form-group-sm">
        <label class="am-u-sm-4 am-u-md-3 am-text-right am-form-label">是否显示</label>
        <div class="am-u-sm-8 am-u-md-9">
          <label class="am-radio-inline">
            <input type="radio" name="navigation.isVisible" value="true"<%if (isAdd || navigation.isVisible == true){%> checked<%}%> required> 是
          </label>
          <label class="am-radio-inline">
            <input type="radio" name="navigation.isVisible" value="false"<%if (navigation.isVisible! == false){%> checked<%}%>> 否
          </label>
          <div class="am-text-warning am-margin-top-xs am-text-xs">${isVisibleMessages!}</div>
        </div>
      </div>
      <div class="am-form-group am-form-group-sm">
        <label class="am-u-sm-4 am-u-md-3 am-text-right am-form-label">新窗口中打开</label>
        <div class="am-u-sm-8 am-u-md-9">
          <label class="am-radio-inline">
            <input type="radio" name="navigation.isBlankTarget" value="true"<%if (navigation.isBlankTarget! == true){%> checked<%}%> required> 是
          </label>
          <label class="am-radio-inline">
            <input type="radio" name="navigation.isBlankTarget" value="false"<%if (isAdd || navigation.isBlankTarget == false){%> checked<%}%>> 否
          </label>
          <div class="am-text-warning am-margin-top-xs am-text-xs">${isBlankTargetMessages!}</div>
        </div>
      </div>
      <div class="am-form-group am-form-group-sm">
        <label class="am-u-sm-4 am-u-md-3 am-text-right am-form-label">排序</label>
        <div class="am-u-sm-8 am-u-md-9">
          <input type="number" class="am-form-field" name="navigation.orderList" value="${navigation.orderList!50}" placeholder="只允许输入零或正整数" min="0" max="1000" required />
          <div class="am-text-warning am-margin-top-xs am-text-xs">${orderListMessages!}</div>
        </div>
      </div>
      <hr data-am-widget="divider" class="am-divider am-divider-dashed" />
      <div class="am-form-group am-form-group-sm">
        <div class="am-u-sm-8 am-u-sm-offset-4 am-u-md-9 am-u-md-offset-3">
          <button type="submit" class="am-btn am-btn-primary"><span class="am-icon-save">  保  存</span></button>
          <button type="button" class="am-btn am-btn-default" onclick="window.history.back(); return false;"><span class="am-icon-undo">  返  回</span></button>
        </div>
      </div>
    </div>
  </form>
  </div>
</div>
<script>
  $(document).ready( function() {
    // 将选择的系统内容地址填充至链接地址中,若名称为空,则自动将名称填充至名称输入框.
    $name = $("#name");
    $systemUrl = $("#systemUrl");
    $url = $("#url");
    $systemUrl.change( function() {
      var url = $systemUrl.val();
      if(url){
        $url.val(url);
        if($name.val() == "") {
          var systemUrlSelectedText = $("#systemUrl").find("option:selected").text();
          if(systemUrlSelectedText){
            systemUrlSelectedText = systemUrlSelectedText.replace(/^-*\s*/g,"");
            $name.val(systemUrlSelectedText);
          }
        }
      }
    });
    // 链接地址内容修改时，系统内容选择框修改为不选择任何项目
    $url.keypress( function() {
        $systemUrl.find('option').eq('').attr('selected', true);
        $systemUrl.val('');
    });
  })
</script>
</body>
</html>
